package com.hmdp.interceptor;


import com.hmdp.utils.UserHolder;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*
* 用户登录拦截器
* */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断当前线程是否有用户信息
        if(UserHolder.getUser() == null){
            //没有则拦截
            response.setStatus(401);
            return false;
        }
        //有则放行
        return true;
    }

}
